<template>
	<view class="container">
		<uni-nav-bar class="ch-nav" height="88rpx" backgroundColor="#ffffff" leftWidth="150rpx" rightWidth="150rpx" color="#333" :fixed="true" :padding="false" :border="true" @clickLeft="$goBack(1)" @clickRight="dropDown = !dropDown">
			<template slot="left">
				<image class="left" src="@/public/images/public/dhl_fhjt.png" mode="aspectFit"></image>
			</template>
			<text class="title">声望值明细</text>
			<template slot="right">
				<view class="tab-select">
					<view class="current-item flex-r ac">
						<text class="text-secondary">{{tabList[tabCur].text}}</text>
						<image class="drop-icon" :src="dropDown ? require('@/public/images/member/xs.png') : require('@/public/images/member/xx.png')" mode="aspectFit"></image>
					</view>
					
				</view>
			</template>
		</uni-nav-bar>
		<view class="select-list flex-c" :class="{'show': dropDown}">
			<view class="list-triangle"></view>
			<view class="list-body flex-c">
				<text class="select-item text-regular" v-for="(item, index) in tabList" :key="index" @tap="tabChange(index)">{{item.text}}</text>
			</view>
		</view>
		<view class="body bottom-ios">
			<view class="renown-list">
				<view class="renown-item flex-r ac" v-for="(renown, index) in renownList" :key="index">
					<view class="item-left flex-c">
						<text class="text-primary">{{actionList[renown.scoreType]}}</text>
						<text class="text-small color-grey mt20">{{renown.createTime}}</text>
					</view>
					<view class="item-right flex-c">
						<text class="text-regular" :class="renown.score > 0 ? 'color-blue' : 'color-red'">{{ renown.score > 0 ? '+'+renown.score : renown.score}}</text>
						<text class="text-small color-grey mt20">声望值</text>
					</view>
				</view>
			</view>
			<view class="list-end flex-r pb20" v-if="renownList[0] && isEnd">
				<text>已经到底啦～</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [
					{ value: 0, text: "全部" },
					{ value: 1, text: "昨天" },
					{ value: 2, text: "近7天" },
					{ value: 3, text: "近30天" },
				],
				tabCur: 0,
				dropDown: false,
				
				renownList: [],
				pageNo: 1,
				isEnd: false,
				
				actionList: {
					1: '浏览',
					2: '点赞',
					3: '留言/回复',
					4: '被留言/回复',
					5: '被点赞',
					6: '发布方案/话题帖/投票帖',
					7: '投诉/建议',
					8: '邀请好友',
					9: '被球吧禁言',
					10: '被球吧删除',
					11: '被删方案/话题帖/投票帖',
					12: '被删留言/回复',
					13: '兑换优惠券'
				}
			};
		},
		onLoad() {
			this.getRenownList()
		},
		onPageScroll() {
			if(this.dropDown){
				this.dropDown = false
			}
		},
		onReachBottom() {
			if(!this.isEnd){
				this.getRenownList()
			}
		},
		methods: {
			//声望值明细
			getRenownList() {
				this.$http.get({
					url: '/api/forum/score/list',
					data: {
						pageNo: this.pageNo,
						pageSize: 15,
						type: this.tabList[this.tabCur].value
					}
				}).then((data) => {
					console.log(data);
					if(data.success && data.result && data.result.total){
						if(data.result.current == 1){
							this.renownList = data.result.records
						}else{
							this.renownList.push(...data.result.records)
						}
						this.isEnd = data.result.current >= data.result.pages
						this.pageNo = data.result.current + 1
					}
				}).catch((error) => {
					console.log(error);
				})
			},
			//类型切换
			tabChange(index) {
				this.dropDown = false
				this.tabCur = index
				this.pageNo = 1
				this.isEnd = false
				this.getRenownList()
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		position: relative;
	}
	.ch-nav{
		.tab-select{
			margin-right: 20rpx;
			position: relative;
			.current-item{
				.drop-icon{
					margin-left: 8rpx;
					width: 16rpx;
					height: 16rpx;
				}
			}
		}
	}
	.select-list{
		position: absolute;
		top: calc(#{$navbar-height} + 20rpx);
		right: 20rpx;
		min-width: 200rpx;
		border-radius: 8rpx;
		background-color: transparent;
		box-sizing: border-box;
		box-shadow: 0rpx 0rpx 10rpx 10rpx rgba(237,237,237,0.6);
		opacity: 0;
		transition: opacity 0.2s ease-in-out;
		&.show{
			opacity: 1;
		}
		.list-triangle{
			position: absolute;
			top: -18rpx;
			right: 20rpx;
			width: 25rpx;
			height: 18rpx;
			background-color: #fff;
			box-shadow: 0rpx 0rpx 10rpx 10rpx rgba(237,237,237,0.6);
			clip-path: polygon(50% 0%, 0 100%, 100% 100%);
		}
		.list-body{
			background-color: #fff;
			.select-item{
				padding: 30rpx;
				&:active{
					background-color: #efefef;
				}
			}
		}
	}
	.body{
		margin: 20rpx 0 0;
		.renown-list{
			margin-bottom: 20rpx;
			.renown-item{
				width: 100%;
				height: 120rpx;
				padding: 0 20rpx;
				background: #FFFFFF;
				border-bottom: 1rpx solid #EDEDED;
				box-sizing: border-box;
				.item-left{
					flex: 2;
					.text-primary{
						font-weight: 500;
					}
				}
				.item-right{
					align-items: flex-end;
					.text-regular{
						font-weight: 500;
					}
				}
			}
			.renown-item:last-child{
				border-bottom: none;
			}
		}
	}
</style>
